package JSON;

import JSON.JSONLexer;
import JSON.JSONParser;
import JSON.JSON2XML;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

import java.io.BufferedReader;
import java.io.FileReader;

public class JSONMain {
    public static void main(String[] args) throws Exception{
        BufferedReader reader = new BufferedReader(new FileReader
                ("D:\\2024.8-2025.1\\compile\\demo\\src\\main\\java\\JSON\\json.txt"));
        ANTLRInputStream inputStream = new ANTLRInputStream(reader);
        JSONLexer lexer = new JSONLexer(inputStream);
        CommonTokenStream tokenStream = new CommonTokenStream(lexer);
        JSONParser parser = new JSONParser(tokenStream);
        ParseTree parseTree = parser.json();
        System.out.println(parseTree.toStringTree());

        ParseTreeWalker walker = new ParseTreeWalker();
        JSON2XML listener = new JSON2XML();
        walker.walk(listener, parseTree);

        String xml = listener.getXml(parseTree);
        System.out.println(xml);
    }
}
